{% extends 'base.html' %}

{% load staticfiles %}

{% block title %}
    课程机构列表
{% endblock %}

{% block custom_bread_tail %}
    <li>课程机构</li>
{% endblock %}

{% block content %}
    <section>
        <div class="wp butler_list_box list">
            <div class='left'>
                <div class="listoptions">
                    <ul>
                        <li>
                            <h2>机构类别</h2>
                            <div class="cont">
                                <a href="?city={{ cur_city_id }}"><span{% if category == '' %} class="active2"{% endif %}>全部</span></a>
                                <a href="?ct=pxjg&city={{ cur_city_id }}"><span{% if category == 'pxjg' %} class="active2"{% endif %}>培训机构</span></a>
                                <a href="?ct=gx&city={{ cur_city_id }}"><span{% if category == 'gx' %} class="active2"{% endif %}>高校</span></a>
                                <a href="?ct=gr&city={{ cur_city_id }}"><span{% if category == 'gr' %} class="active2"{% endif %}>个人</span></a>
                            </div>
                        </li>
                        <li>
                            <h2>所在地区</h2>
                            <div class="more">更多</div>
                            <div class="cont">
                                <a href="?ct={{ category }}"><span{% if cur_city_id == '' %} class="active2"{% endif %}>全部</span></a>
                                {# 城市列表 #}
                                {% for city in all_cities %}
                                    <a href="?city={{ city.id }}&ct={{ category }}">
                                        <span{% if cur_city_id == city.id|stringformat:'i' %} class="active2"{% endif %}>
                                            {{ city }}
                                        </span>
                                    </a>
                                {% endfor %}
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="all">共<span class="key">{{ org_nums }}</span>家</div>
                <div class="butler_list company list">
                    <div class="layout">
                        <div class="head">
                            <ul class="tab_header">
                                <li{% if sort == '' %} class="active"{% endif %}><a href="?ct={{ category }}&city={{ cur_city_id }}">全部</a></li>
                                <li{% if sort == 'students' %} class="active"{% endif %}><a href="?sort=students&ct={{ category }}&city={{ cur_city_id }}">
                                    学习人数 &#8595;</a></li>
                                <li{% if sort == 'courses' %} class="active"{% endif %}><a href="?sort=courses&ct={{ category }}&city={{ cur_city_id }}">
                                    课程数 &#8595;</a></li>
                            </ul>
                        </div>
                        {# 机构列表 #}
                        {% for org in org_paginator.object_list %}
                            <dl class="des difdes">
                            <dt>
                                <a href="{% url 'org:org_home' org.id %}">
                                    <img width="200" height="120" class="scrollLoading"
                                         data-url="{{ MEDIA_URL }}{{ org.image }}"/>
                                </a>
                            </dt>
                            <dd>
                                <div class="clearfix">
                                    <a href="{% url 'org:org_home' org.id %}">
                                        <h1>{{ org.name }}</h1>
                                        <div class="pic fl">
                                            <img src="{% static 'images/authentication.png' %}"/>
                                            <img src="{% static 'images/gold.png' %}"/>
                                        </div>
                                    </a>
                                </div>
                                <ul class="cont">
                                    <li class="first"><p class="pic9">课程数：<span>{{ org.course_nums }}</span></p>
                                        <p class="c7">学习人数：<span>{{ org.student_nums }}</span></p></li>
                                    <li class="c8" style="padding-left:18px;">{{ org.address }}</li>
                                    <li class="pic10" style="padding-left:18px;">经典课程：

                                        <a href="/diary/19/">需要填充</a>

                                        <a href="/diary/16/">需要填充</a>

                                    </li>
                                </ul>
                            </dd>
                            <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
                        </dl>
                        {% endfor %}
                    </div>

                    {# 分页 #}
                    {% load i18n %}
                    <div class="pageturn">
                        <ul class="pagelist">

                            {# 上一页 #}
                            {% if org_paginator.has_previous %}
                                <li class="long">
                                    {# *.querystring 如: 'page=1' #}
                                    <a href="?{{ org_paginator.previous_page_number.querystring }}">
                                        上一页
                                    </a>
                                </li>
                            {% endif %}

                            {# 分页主体 #}
                            {% for page in org_paginator.pages %}
                                {# p.pages返回如: 1, 2, None, 5, 6, None, 9 #}
                                {% if page %}
                                    {# 当前页面高亮显示 #}
                                    <li{% if page == org_paginator.number %} class="active"{% endif %}>
                                        <a href="?{{ page.querystring }}">
                                            {{ page }}
                                        </a>
                                    </li>
                                {% else %}
                                    <li>...</li>
                                {% endif %}
                            {% endfor %}

                            {# 下一页 #}
                            {% if org_paginator.has_next %}
                                <li class="long">
                                    <a href="?{{ org_paginator.next_page_number.querystring }}">
                                        下一页
                                    </a>
                                </li>
                            {% endif %}
                        </ul>
                    </div>

                </div>
            </div>
            <div class="right companyright">
                <div class="head">我要学习</div>
                <form class="rightform" id="jsStayForm" method="post" action="{% url 'org:add_ask' %}">
                    <div>
                        <img src="{% static 'images/rightform1.png' %}"/>
                        <input type="text" name="name" id="companyName" placeholder="名字" maxlength="25"/>
                    </div>
                    <div>
                        <img src="{% static 'images/rightform2.png' %}"/>
                        <input type="text" name="mobile" id="companyMobile" placeholder="联系电话"/>
                    </div>
                    <div>
                        <img src="{% static 'images/rightform3.png' %}"/>
                        <input type="text" name="course_name" id="companyAddress" placeholder="课程名" maxlength="50"/>
                    </div>
                    <p class="error company-tips" id="jsCompanyTips"></p>
                    <input class="btn" type="text" id="jsStayBtn" value="立即咨询 >"/>
                    {% csrf_token %}
                </form>
            </div>

            <div class="right companyrank layout">

                <div class="head">授课机构排名</div>
                {% for org in hot_orgs %}
                    <dl class="des">
                        <dt class="num fl">{{ forloop.counter }}</dt>
                        <dd>
                            <a href="{% url 'org:org_home' org.id %}"><h1>{{ org.name }}</h1></a>
                            <p>{{ org.address }}</p>
                        </dd>
                    </dl>
                {% endfor %}

            </div>
        </div>
    </section>
{% endblock %}

{% block custom_js %}
    <script>
        $(function () {
            $('#jsStayBtn').on('click', function () {
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: '{% url 'org:add_ask' %}',
                    data: $('#jsStayForm').serialize(),
                    async: true,
                    success: function (data) {
                        if (data.status == 'success'){
                            $('#jsStayForm')[0].reset();
                            $('#jsStayBtn').val('提交成功');
                            $('#jsStayBtn').css({background: '#4FB137'})
                        } else if(data.status == 'fail'){
                            $('#jsStayBtn').val('提交出错');
                        }
                    }
                })
            })
        })
    </script>
{% endblock %}